#include "configwindow.h"
#include "ui_configwindow.h"

ConfigWindow::ConfigWindow(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::ConfigWindow)
{
    ui->setupUi(this);
    setAttribute(Qt::WA_StyledBackground);
//    resize(500, 400);
}

ConfigWindow::~ConfigWindow()
{
    delete ui;
}

void ConfigWindow::paintEvent(QPaintEvent *event)
{
    // 移动至屏幕中央
    QWidget *pa = dynamic_cast<QWidget*>(parent());
    QSize s = pa->size();
    move(s.width() / 2 - size().width() / 2, s.height() / 5);
}

void ConfigWindow::on_pushButton_4_clicked()
{
    hide();
}


void ConfigWindow::on_pushButton_3_clicked()
{
    // 清除浏览器缓存
    profile->clearHttpCache();
}


void ConfigWindow::on_radioButton_toggled(bool checked)
{
    qDebug() << "无痕模式状态：" << checked;
    if(checked){
        // 无痕模式，不进行cookie数据的持久化
        profile->setPersistentCookiesPolicy(QWebEngineProfile::NoPersistentCookies);

    }else{
        // 正常模式，允许进行cookie等数据的持久化
        profile->setPersistentCookiesPolicy(QWebEngineProfile::AllowPersistentCookies);
    }
}


void ConfigWindow::on_pushButton_clicked()
{
    // 清除历史记录
    HistoryManager::getInstance().clearHistory();
}


void ConfigWindow::on_pushButton_2_clicked()
{
    // 设置浏览器代理
    QString proxyText = this->ui->lineEdit->text();
    if(proxyText != ""){
        profile->setHttpUserAgent(proxyText);
    }
}

